package com.yxw.yxnet_cd_center.customer_service.controller;

import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.customer_service.dto.GroupAddDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.GroupQueryDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.StatusUpdateDTO;
import com.yxw.yxnet_cd_center.customer_service.service.GroupService;
import com.yxw.yxnet_cd_center.customer_service.vo.YxCsGroupVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 工作组管理
 * @author liuxin
 * @date 2023.09.14
 */
@RestController
@Api(value = "工作组管理", tags = "工作组管理")
@Slf4j
@RequestMapping("/group")
public class GroupController {

    @Autowired
    private GroupService  groupService;

    @ApiOperation(value = "工作流管理-工作组列表查询")
    @PostMapping(value = "/getGroupList")
    public BaseResult<PageVO<YxCsGroupVo>> getGroupList(@RequestBody GroupQueryDTO dto) {
        PageVO<YxCsGroupVo> pageVo=groupService.getGroupList(dto);
        return ResultHelper.fillWithSuccess(pageVo);
    }

    @ApiOperation(value = "工作流管理-新增工作组")
    @PostMapping(value = "/addGroup")
    public BaseResult addGroup(@RequestBody @Validated GroupAddDTO dto) {
        YxCsGroupVo vo=groupService.addGroup(dto);
        return BaseResult.doSuccess(vo,"新增成功");
    }

    @ApiOperation(value = "工作流管理-更新工作组")
    @PostMapping(value = "/updateGroup")
    public BaseResult updateGroup(@RequestBody @Validated GroupAddDTO dto) {
        groupService.updateGroup(dto);
        return BaseResult.doSuccess(null,"更新成功");
    }

    @ApiOperation(value = "工作流管理-删除工作组")
    @DeleteMapping(value = "/deleteGroupById")
    public BaseResult deleteGroupById( Long id) {
        groupService.deleteGroupById(id);
        return BaseResult.doSuccess(null,"删除成功");
    }


    @ApiOperation(value = "工作组分群-工作组列表查询")
    @PostMapping(value = "/getFlockGroupList")
    public BaseResult<PageVO<YxCsGroupVo>> getFlockGroupList(@RequestBody GroupQueryDTO dto) {
        PageVO<YxCsGroupVo> pageVo=groupService.getFlockGroupList(dto);
        return ResultHelper.fillWithSuccess(pageVo);
    }

    @ApiOperation(value = "工作组分群-工作组启用/禁用")
    @PostMapping(value = "/updateGroupStatusById")
    public BaseResult updateGroupStatusById(@RequestBody @Valid  StatusUpdateDTO dto) {
        groupService.updateGroupStatusById(dto);
        return BaseResult.doSuccess(null,"修改成功");
    }

    @ApiOperation(value = "工作流管理-工作组详情查询")
    @GetMapping(value = "/getGroupById")
    public BaseResult<YxCsGroupVo> getGroupById(@RequestParam(value = "id")Long groupId) {
        YxCsGroupVo vo=groupService.getGroupById(groupId);
        return BaseResult.doSuccess(vo,"查询成功");
    }
}
